package com.freely.util;

import java.util.Arrays;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.PropertyFilter;
import com.alibaba.fastjson.serializer.SerializeFilter;

public class JSONUtil {
	// 过滤掉不想要的字段
	public static SerializeFilter jsonFilter(String...keys) {
		if(keys == null || keys.length == 0) {
			return null;
		}
		final List<String> list = Arrays.asList(keys);
		PropertyFilter filter = new PropertyFilter() {
			@Override
			// obj 为整个json数据，key为当前扫描到的某个字段的字段名，value为某个字段的值
			public boolean apply(Object obj, String key, Object value) {
				if(list.contains(key)) {
					return false;
				}
				return true;
			}
			
		};
		return filter;
	}
}
